﻿using ShopManagement.Model.EF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ShopManagement
{
    internal class UserService
    {//获得用户数据库
        public List<Users> GetAll()
        {
            var db = new Shop2024Entities();
            return db.Users.ToList();
        }
        // 文件：UserService.cs
        public Users GetUserById(int userId)
        {
            using (var db = new Shop2024Entities())
            {
                return db.Users.FirstOrDefault(u => u.UserID == userId);
            }
        }
        public void UpdateUser(Users user)
        {
            using (var db = new Shop2024Entities())
            {
                var existingUser = db.Users.FirstOrDefault(u => u.UserID == user.UserID);
                if (existingUser != null)
                {
                    existingUser.UserName = user.UserName;
                    existingUser.UserEmail = user.UserEmail;
                    existingUser.UserPassword = user.UserPassword;
                    existingUser.UserNumber = user.UserNumber;
                    db.SaveChanges();
                }
            }
        }
    }
}
